#include <sys/stat.h>
#include <sys/types.h>

#include<Global.h>
#include<TELFile.h>
#include<TELTrack.h>

#include<TApplication.h>
#include<TStyle.h>

int main(int argc, char* argv[]){
  
  Int_t RunNumber = atoi(argv[1]);

  TApplication app("myapp", &argc, argv);
  
  gStyle->SetOptFit(1);
  gStyle->SetPalette(1);

  Char_t results[100];
  sprintf(results,"./ntuple/dut/%d",RunNumber);
  
  cout << mkdir(results,0777) << endl;

  {
    TELFile ff(RunNumber);
    //ff.SimplePedNoi();//Finds pedestal and noise for run without beam
    ff.PedNoi();//Finds pedestal and noise
    ff.FindClusters(3,3);//Finds clusters and perform prealignment 
    ff.HitNtupl(3,3);//Builds hit ntuple
    ff.HitNtuplWithEta(3,3,200);//Builds hit ntuple
    TELTrack track(RunNumber);
    track.PlotTracks();//Makes info plots for line tracks
  }
  
  app.Run(true);
  
}
